define(['PIXI', '../vendor/kobako/logger.js'], (PIXI, Logger) => {
    function initial_texts(line_num) {
        const style = new PIXI.TextStyle({ fontSize: 15, fill: 'red' })
        const result = []
        for (let i = 0; i < line_num; i++) {
            const text = new PIXI.Text('Initial text', style)
            text.y = i * 20
            text.visible = false
            // container.addChild(text)
            result.push(text)
        }
        return result
    }

    class GameLogger {
        constructor(life_span, container, view) {
            this.life_span = life_span
            this.container = container
            this.logger = new Logger(life_span)

            const texts = initial_texts(5)
            texts.forEach(t => {
                container.addChild(t)
                view.add(t)
            })
            
            this.add('Inited logger')
        }
        update_showing() {
            const showings = this.logger.get_showing()
            // console.log(showings.length)
            this.container.children.forEach((log, index) => {
                if (showings[index] != null) {
                    // console.log(showings[index])
                    log.text = showings[index]
                    log.visible = true
                } else {
                    log.visible = false
                }
            })
        }
        update() { //Tick
            // console.log('log')
            this.logger.update()
            this.update_showing()
        }
        add(text) {
            this.logger.add(text)
            this.update_showing()
        }
    }

    return GameLogger
})